package com.qf.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Result;
import java.io.IOException;

/**
 * @author Lyx on 2022/5/17
 */
@WebServlet(name = "RegistServlet ",urlPatterns ="/register")
public class RegistServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.设置编码
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        //2获取页面传入的参数
        String name = request.getParameter("name");
        //3 判断以及实现 业务
        String result=null;
        if(name.equals("root")||name.equals("admin")){
            //2代表该用户已经存在
            result="2";
        }else{
            //该用户可以注册
            result="1";
        }
        //4.通过 响应写数据到页面
        response.getWriter().write(result);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
